home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / AlgoWaveTableList.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  27.4 KB  |  852 lines  |  [TEXT/KAHL]

  1. /* AlgoWaveTableList.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "AlgoWaveTableList.h"
  31. #include "StringList.h"
  32. #include "Array.h"
  33. #include "Memory.h"
  34. #include "Alert.h"
  35. #include "DataMunging.h"
  36. #include "AlgoWaveTableObject.h"
  37. #include "BufferedFileInput.h"
  38. #include "BufferedFileOutput.h"
  39. #include "Files.h"
  40. #include "Scrap.h"
  41.  
  42.  
  43. struct AlgoWaveTableListRec
  44.     {
  45.         StringListRec*                    List;
  46.         struct CodeCenterRec*        CodeCenter;
  47.         struct MainWindowRec*        MainWindow;
  48.         ArrayRec*                                AlgoWaveTableArray;
  49.         MyBoolean                                AlgoWaveTableListChanged;
  50.     };
  51.  
  52.  
  53. #define MAGICSCRAPSTRING ("\xff\x00\x1f\xfe AlgoWaveTableObjectScrap")
  54.  
  55.  
  56. AlgoWaveTableListRec*    NewAlgoWaveTableList(struct MainWindowRec* MainWindow,
  57.                                             struct CodeCenterRec* CodeCenter, WinType* ScreenID,
  58.                                             OrdType XLoc, OrdType YLoc, OrdType Width, OrdType Height)
  59.     {
  60.         AlgoWaveTableListRec*    AlgoWaveTableList;
  61.  
  62.         AlgoWaveTableList = (AlgoWaveTableListRec*)AllocPtrCanFail(sizeof(AlgoWaveTableListRec),
  63.             "AlgoWaveTableListRec");
  64.         if (AlgoWaveTableList == NIL)
  65.             {
  66.              FailurePoint1:
  67.                 return NIL;
  68.             }
  69.         AlgoWaveTableList->AlgoWaveTableArray = NewArray();
  70.         if (AlgoWaveTableList->AlgoWaveTableArray == NIL)
  71.             {
  72.              FailurePoint2:
  73.                 ReleasePtr((char*)AlgoWaveTableList);
  74.                 goto FailurePoint1;
  75.             }
  76.         AlgoWaveTableList->List = NewStringList(ScreenID,XLoc,YLoc,Width,Height,
  77.             GetScreenFont(),9,StringListDontAllowMultipleSelection,"Algorithmic Wave Tables");
  78.         if (AlgoWaveTableList->List == NIL)
  79.             {
  80.              FailurePoint3:
  81.                 DisposeArray(AlgoWaveTableList->AlgoWaveTableArray);
  82.                 goto FailurePoint2;
  83.             }
  84.         AlgoWaveTableList->CodeCenter = CodeCenter;
  85.         AlgoWaveTableList->MainWindow = MainWindow;
  86.         AlgoWaveTableList->AlgoWaveTableListChanged = False;
  87.         return AlgoWaveTableList;
  88.     }
  89.  
  90.  
  91. /* delete the algorithmic wave table list and all of the wave tables it contains */
  92. void                                DisposeAlgoWaveTableList(AlgoWaveTableListRec* AlgoWaveTableList)
  93.     {
  94.         long                            Scan;
  95.         long                            Limit;
  96.  
  97.         CheckPtrExistence(AlgoWaveTableList);
  98.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  99.         for (Scan = 0; Scan < Limit; Scan += 1)
  100.             {
  101.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  102.  
  103.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  104.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  105.                 DisposeAlgoWaveTableObject(AlgoWaveTableTemp);
  106.             }
  107.         DisposeArray(AlgoWaveTableList->AlgoWaveTableArray);
  108.         DisposeStringList(AlgoWaveTableList->List);
  109.         ReleasePtr((char*)AlgoWaveTableList);
  110.     }
  111.  
  112.  
  113. /* change the location of the algorithmic wave table list in the window */
  114. void                                SetAlgoWaveTableListLocation(AlgoWaveTableListRec* AlgoWaveTableList,
  115.                                             OrdType XLoc, OrdType YLoc, OrdType Width, OrdType Height)
  116.     {
  117.         CheckPtrExistence(AlgoWaveTableList);
  118.         SetStringListLoc(AlgoWaveTableList->List,XLoc,YLoc,Width,Height);
  119.     }
  120.  
  121.  
  122. /* redraw the list */
  123. void                                AlgoWaveTableListRedraw(AlgoWaveTableListRec* AlgoWaveTableList)
  124.     {
  125.         CheckPtrExistence(AlgoWaveTableList);
  126.         RedrawStringList(AlgoWaveTableList->List);
  127.     }
  128.  
  129.  
  130. /* see if the specified coordinates falls inside the wave table list rectangle */
  131. MyBoolean                        AlgoWaveTableListHitTest(AlgoWaveTableListRec* AlgoWaveTableList,
  132.                                             OrdType XLoc, OrdType YLoc)
  133.     {
  134.         CheckPtrExistence(AlgoWaveTableList);
  135.         return StringListHitTest(AlgoWaveTableList->List,XLoc,YLoc);
  136.     }
  137.  
  138.  
  139. /* handle a mouse down event for the algorithmic wave table list */
  140. void                                AlgoWaveTableListDoMouseDown(AlgoWaveTableListRec* AlgoWaveTableList,
  141.                                             OrdType XLoc, OrdType YLoc, ModifierFlags Modifiers)
  142.     {
  143.         CheckPtrExistence(AlgoWaveTableList);
  144.         if (StringListMouseDown(AlgoWaveTableList->List,XLoc,YLoc,Modifiers))
  145.             {
  146.                 /* if it returns true, then it was a double click */
  147.                 AlgoWaveTableListOpenSelection(AlgoWaveTableList);
  148.             }
  149.     }
  150.  
  151.  
  152. /* called when the window becomes active */
  153. void                                AlgoWaveTableListBecomeActive(AlgoWaveTableListRec* AlgoWaveTableList)
  154.     {
  155.         CheckPtrExistence(AlgoWaveTableList);
  156.         EnableStringList(AlgoWaveTableList->List);
  157.     }
  158.  
  159.  
  160. /* called when the window becomes inactive */
  161. void                                AlgoWaveTableListBecomeInactive(AlgoWaveTableListRec* AlgoWaveTableList)
  162.     {
  163.         CheckPtrExistence(AlgoWaveTableList);
  164.         DisableStringList(AlgoWaveTableList->List);
  165.     }
  166.  
  167.  
  168. /* called when a selection is made in another list, so that this list */
  169. /* is deselected */
  170. void                                AlgoWaveTableListDeselect(AlgoWaveTableListRec* AlgoWaveTableList)
  171.     {
  172.         CheckPtrExistence(AlgoWaveTableList);
  173.         DeselectAllStringListElements(AlgoWaveTableList->List);
  174.     }
  175.  
  176.  
  177. /* check to see if there is a selection in this list */
  178. MyBoolean                        AlgoWaveTableListIsThereSelection(AlgoWaveTableListRec* AlgoWaveTableList)
  179.     {
  180.         CheckPtrExistence(AlgoWaveTableList);
  181.         return (GetStringListHowManySelectedItems(AlgoWaveTableList->List) > 0);
  182.     }
  183.  
  184.  
  185. /* check to see if any of the algorithmic wave tables contained in this list need */
  186. /* to be saved */
  187. MyBoolean                        DoesAlgoWaveTableListNeedToBeSaved(AlgoWaveTableListRec* AlgoWaveTableList)
  188.     {
  189.         long                            Scan;
  190.         long                            Limit;
  191.         MyBoolean                    Flag;
  192.  
  193.         CheckPtrExistence(AlgoWaveTableList);
  194.         Flag = AlgoWaveTableList->AlgoWaveTableListChanged;
  195.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  196.         for (Scan = 0; (Scan < Limit) && !Flag; Scan += 1)
  197.             {
  198.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  199.  
  200.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  201.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  202.                 if (HasAlgoWaveTableObjectBeenModified(AlgoWaveTableTemp))
  203.                     {
  204.                         Flag = True;
  205.                     }
  206.             }
  207.         return Flag;
  208.     }
  209.  
  210.  
  211. /* open an edit window for the selected algorithmic wave table */
  212. void                                AlgoWaveTableListOpenSelection(AlgoWaveTableListRec* AlgoWaveTableList)
  213.     {
  214.         ArrayRec*                    ListOfSelections;
  215.  
  216.         CheckPtrExistence(AlgoWaveTableList);
  217.         ListOfSelections = GetListOfSelectedItems(AlgoWaveTableList->List);
  218.         if (ListOfSelections != NIL)
  219.             {
  220.                 long                            Scan;
  221.                 long                            Limit;
  222.  
  223.                 Limit = ArrayGetLength(ListOfSelections);
  224.                 for (Scan = 0; Scan < Limit; Scan += 1)
  225.                     {
  226.                         AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  227.  
  228.                         AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  229.                             ListOfSelections,Scan);
  230.                         AlgoWaveTableObjectOpenWindow(AlgoWaveTableTemp);
  231.                     }
  232.                 DisposeArray(ListOfSelections);
  233.             }
  234.     }
  235.  
  236.  
  237. /* create a new algorithmic wave table and open a window for it */
  238. void                                AlgoWaveTableListNewAlgoWaveTable(AlgoWaveTableListRec* AlgoWaveTableList)
  239.     {
  240.         AlgoWaveTableObjectRec*    AlgoWaveTable;
  241.  
  242.         CheckPtrExistence(AlgoWaveTableList);
  243.         /* create the object */
  244.         AlgoWaveTable = NewAlgoWaveTableObject(AlgoWaveTableList->CodeCenter,
  245.             AlgoWaveTableList->MainWindow,AlgoWaveTableList);
  246.         if (AlgoWaveTable == NIL)
  247.             {
  248.              FailurePoint1:
  249.                 AlertHalt("There is not enough memory available to create a new algorithmic "
  250.                     "wave table.",NIL);
  251.                 return;
  252.             }
  253.         /* add it to the string list */
  254.         if (!InsertStringListElement(AlgoWaveTableList->List,NIL,NIL,AlgoWaveTable,True))
  255.             {
  256.              FailurePoint2:
  257.                 DisposeAlgoWaveTableObject(AlgoWaveTable);
  258.                 goto FailurePoint1;
  259.             }
  260.         MainWindowDeselectAllOtherStringLists(AlgoWaveTableList->MainWindow,AlgoWaveTableList);
  261.         SelectStringListElement(AlgoWaveTableList->List,AlgoWaveTable);
  262.         MakeStringListSelectionVisible(AlgoWaveTableList->List);
  263.         /* add it to the array */
  264.         if (!ArrayAppendElement(AlgoWaveTableList->AlgoWaveTableArray,AlgoWaveTable))
  265.             {
  266.              FailurePoint3:
  267.                 RemoveStringListElement(AlgoWaveTableList->List,AlgoWaveTable,True);
  268.                 goto FailurePoint2;
  269.             }
  270.         /* update our internal flags */
  271.         AlgoWaveTableList->AlgoWaveTableListChanged = True;
  272.         /* change the name in the list */
  273.         AlgoWaveTableListAlgoWaveTableNameChanged(AlgoWaveTableList,AlgoWaveTable);
  274.         /* show the window */
  275.         AlgoWaveTableObjectOpenWindow(AlgoWaveTable);
  276.     }
  277.  
  278.  
  279. /* delete the selected algorithmic wave table */
  280. void                                AlgoWaveTableListDeleteSelection(AlgoWaveTableListRec* AlgoWaveTableList)
  281.     {
  282.         ArrayRec*                    ListOfSelections;
  283.  
  284.         CheckPtrExistence(AlgoWaveTableList);
  285.         ListOfSelections = GetListOfSelectedItems(AlgoWaveTableList->List);
  286.         if (ListOfSelections != NIL)
  287.             {
  288.                 long                                Scan;
  289.                 long                                Limit;
  290.  
  291.                 Limit = ArrayGetLength(ListOfSelections);
  292.                 for (Scan = 0; Scan < Limit; Scan += 1)
  293.                     {
  294.                         AlgoWaveTableObjectRec*    OneToZap;
  295.  
  296.                         OneToZap = (AlgoWaveTableObjectRec*)ArrayGetElement(ListOfSelections,Scan);
  297.                         AlgoWaveTableListDeleteAlgoWaveTable(AlgoWaveTableList,OneToZap);
  298.                     }
  299.                 DisposeArray(ListOfSelections);
  300.             }
  301.     }
  302.  
  303.  
  304. /* delete the explicitly specified algorithmic wave table */
  305. void                                AlgoWaveTableListDeleteAlgoWaveTable(AlgoWaveTableListRec* AlgoWaveTableList,
  306.                                             struct AlgoWaveTableObjectRec* TheAlgoWaveTable)
  307.     {
  308.         long                                Scan;
  309.         long                                Limit;
  310.  
  311.         CheckPtrExistence(AlgoWaveTableList);
  312.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  313.         for (Scan = 0; Scan < Limit; Scan += 1)
  314.             {
  315.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  316.  
  317.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  318.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  319.                 if (TheAlgoWaveTable == AlgoWaveTableTemp)
  320.                     {
  321.                         FileSpec*                    BackupFileWhere;
  322.                         FileType*                    BackupFile;
  323.                         MyBoolean                    Success = False;
  324.  
  325.                         BackupFileWhere = NewTempFileSpec(CODE4BYTES('?','?','?','?'),
  326.                             CODE4BYTES('?','?','?','?'));
  327.                         if (BackupFileWhere != NIL)
  328.                             {
  329.                                 if (OpenFile(BackupFileWhere,&BackupFile,eReadAndWrite))
  330.                                     {
  331.                                         BufferedOutputRec*    Output;
  332.  
  333.                                         Output = NewBufferedOutput(BackupFile);
  334.                                         if (Output != NIL)
  335.                                             {
  336.                                                 if (WriteBufferedOutput(Output,sizeof(MAGICSCRAPSTRING),
  337.                                                     MAGICSCRAPSTRING))
  338.                                                     {
  339.                                                         if (AlgoWaveTableObjectWriteDataOut(TheAlgoWaveTable,Output)
  340.                                                             == eFileLoadNoError)
  341.                                                             {
  342.                                                                 Success = True;
  343.                                                             }
  344.                                                     }
  345.                                                 if (!EndBufferedOutput(Output))
  346.                                                     {
  347.                                                         Success = False;
  348.                                                     }
  349.                                             }
  350.                                          else
  351.                                             {
  352.                                                 CloseFile(BackupFile);
  353.                                             }
  354.                                     }
  355.                                  else
  356.                                     {
  357.                                         DeleteFile(BackupFileWhere);
  358.                                         DisposeFileSpec(BackupFileWhere);
  359.                                     }
  360.                             }
  361.                         if (Success)
  362.                             {
  363.                                 MainWindowNewDeleteUndoInfo(AlgoWaveTableList->MainWindow,BackupFileWhere,
  364.                                     BackupFile);
  365.                                 DisposeAlgoWaveTableObject(AlgoWaveTableTemp);
  366.                                 RemoveStringListElement(AlgoWaveTableList->List,AlgoWaveTableTemp,True);
  367.                                 ArrayDeleteElement(AlgoWaveTableList->AlgoWaveTableArray,Scan);
  368.                                 AlgoWaveTableList->AlgoWaveTableListChanged = True;
  369.                             }
  370.                          else
  371.                             {
  372.                                 YesNoCancelType        Decision;
  373.  
  374.                                 Decision = AskYesNoCancel("Unable to save undo information for object.  "
  375.                                     "Delete object anyway?",NIL,"Delete","Cancel",NIL/*nothirdbutton*/);
  376.                                 if (Decision == eYes)
  377.                                     {
  378.                                         DisposeAlgoWaveTableObject(AlgoWaveTableTemp);
  379.                                         RemoveStringListElement(AlgoWaveTableList->List,AlgoWaveTableTemp,True);
  380.                                         ArrayDeleteElement(AlgoWaveTableList->AlgoWaveTableArray,Scan);
  381.                                         AlgoWaveTableList->AlgoWaveTableListChanged = True;
  382.                                     }
  383.                             }
  384.                         return;
  385.                     }
  386.             }
  387.         EXECUTE(PRERR(AllowResume,"AlgoWaveTableListDeleteAlgoWaveTable:  couldn't find object"));
  388.     }
  389.  
  390.  
  391. /* the name of a algorithmic wave table has changed, so the name in the scrolling */
  392. /* list must also be changed */
  393. void                                AlgoWaveTableListAlgoWaveTableNameChanged(AlgoWaveTableListRec* AlgoWaveTableList,
  394.                                             struct AlgoWaveTableObjectRec* TheAlgoWaveTable)
  395.     {
  396.         char*                            AlgoWaveTableName;
  397.  
  398.         CheckPtrExistence(AlgoWaveTableList);
  399.         CheckPtrExistence(TheAlgoWaveTable);
  400.         ERROR(ArrayFindElement(AlgoWaveTableList->AlgoWaveTableArray,TheAlgoWaveTable) < 0,
  401.             PRERR(ForceAbort,"AlgoWaveTableListAlgoWaveTableNameChanged:  unknown algowavetable"));
  402.         AlgoWaveTableName = AlgoWaveTableObjectGetNameCopy(TheAlgoWaveTable);
  403.         if (AlgoWaveTableName != NIL)
  404.             {
  405.                 char*                            AlgoWaveTableNameNullTerminated;
  406.  
  407.                 AlgoWaveTableNameNullTerminated = BlockToStringCopy(AlgoWaveTableName);
  408.                 if (AlgoWaveTableNameNullTerminated != NIL)
  409.                     {
  410.                         ChangeStringListElementName(AlgoWaveTableList->List,
  411.                             AlgoWaveTableNameNullTerminated,TheAlgoWaveTable);
  412.                         ReleasePtr(AlgoWaveTableNameNullTerminated);
  413.                     }
  414.                 ReleasePtr(AlgoWaveTableName);
  415.             }
  416.     }
  417.  
  418.  
  419. /* look for a specified algorithmic wave table.  returns NIL if not found.  the name is */
  420. /* NOT null terminated */
  421. struct AlgoWaveTableObjectRec*    AlgoWaveTableListLookupNamedAlgoWaveTable(
  422.                                             AlgoWaveTableListRec* AlgoWaveTableList, char* Name)
  423.     {
  424.         long                            Scan;
  425.         long                            Limit;
  426.  
  427.         CheckPtrExistence(AlgoWaveTableList);
  428.         CheckPtrExistence(Name);
  429.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  430.         for (Scan = 0; Scan < Limit; Scan += 1)
  431.             {
  432.                 AlgoWaveTableObjectRec*    AlgoWaveTable;
  433.                 char*                                        NameCopy;
  434.  
  435.                 AlgoWaveTable = (AlgoWaveTableObjectRec*)ArrayGetElement(
  436.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  437.                 NameCopy = AlgoWaveTableObjectGetNameCopy(AlgoWaveTable);
  438.                 if (NameCopy != NIL)
  439.                     {
  440.                         if (PtrSize(Name) == PtrSize(NameCopy))
  441.                             {
  442.                                 if (MemEqu(Name,NameCopy,PtrSize(Name)))
  443.                                     {
  444.                                         ReleasePtr(NameCopy);
  445.                                         return AlgoWaveTable;
  446.                                     }
  447.                             }
  448.                         ReleasePtr(NameCopy);
  449.                     }
  450.             }
  451.         return NIL;
  452.     }
  453.  
  454.  
  455. /* remove all data arrays for all algorithmic wave tables */
  456. void                                AlgoWaveTableListUnbuildAll(AlgoWaveTableListRec* AlgoWaveTableList)
  457.     {
  458.         long                            Scan;
  459.         long                            Limit;
  460.  
  461.         CheckPtrExistence(AlgoWaveTableList);
  462.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  463.         for (Scan = 0; Scan < Limit; Scan += 1)
  464.             {
  465.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  466.  
  467.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  468.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  469.                 AlgoWaveTableObjectUnbuild(AlgoWaveTableTemp);
  470.             }
  471.     }
  472.  
  473.  
  474. /* build all algorithmic wave tables.  returns True if successful. */
  475. MyBoolean                        AlgoWaveTableListMakeUpToDate(AlgoWaveTableListRec* AlgoWaveTableList)
  476.     {
  477.         long                            Scan;
  478.         long                            Limit;
  479.  
  480.         CheckPtrExistence(AlgoWaveTableList);
  481.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  482.         for (Scan = 0; Scan < Limit; Scan += 1)
  483.             {
  484.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  485.  
  486.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  487.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  488.                 if (!AlgoWaveTableObjectMakeUpToDate(AlgoWaveTableTemp))
  489.                     {
  490.                         return False;
  491.                     }
  492.             }
  493.         return True;
  494.     }
  495.  
  496.  
  497. /* the document's name has changed, so we need to update the windows */
  498. void                                AlgoWaveTableListGlobalNameChange(AlgoWaveTableListRec*
  499.                                             AlgoWaveTableList, char* NewFilename)
  500.     {
  501.         long                            Scan;
  502.         long                            Limit;
  503.  
  504.         CheckPtrExistence(AlgoWaveTableList);
  505.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  506.         for (Scan = 0; Scan < Limit; Scan += 1)
  507.             {
  508.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  509.  
  510.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  511.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  512.                 AlgoWaveTableObjectGlobalNameChange(AlgoWaveTableTemp,NewFilename);
  513.             }
  514.     }
  515.  
  516.  
  517. /*   4-byte little endian number of algorithmic wave table objects (positive 2s complement) */
  518. /*   n-byte data for all the algorithmic wave table objects */
  519.  
  520.  
  521. /* read algorithmic wave table objects from a file.  returns True if successful. */
  522. FileLoadingErrors        AlgoWaveTableListReadData(AlgoWaveTableListRec* AlgoWaveTableList,
  523.                                             struct BufferedInputRec* Input)
  524.     {
  525.         signed long                NumberOfObjects;
  526.         long                            Scan;
  527.  
  528.         CheckPtrExistence(AlgoWaveTableList);
  529.         CheckPtrExistence(Input);
  530.  
  531.         /*   4-byte little endian number of objects (positive 2s complement) */
  532.         if (!ReadBufferedSignedLongLittleEndian(Input,&NumberOfObjects))
  533.             {
  534.                 return eFileLoadDiskError;
  535.             }
  536.         if (NumberOfObjects < 0)
  537.             {
  538.                 return eFileLoadBadFormat;
  539.             }
  540.  
  541.         /*   n-byte data for all the objects */
  542.         for (Scan = 0; Scan < NumberOfObjects; Scan += 1)
  543.             {
  544.                 AlgoWaveTableObjectRec*    AlgoWaveTable EXECUTE(= (AlgoWaveTableObjectRec*)0x81818181);
  545.                 FileLoadingErrors                Error;
  546.  
  547.                 /* load the object */
  548.                 Error = AlgoWaveTableObjectNewFromFile(&AlgoWaveTable,Input,
  549.                     AlgoWaveTableList->CodeCenter,AlgoWaveTableList->MainWindow,AlgoWaveTableList);
  550.                 if (Error != eFileLoadNoError)
  551.                     {
  552.                      FailurePoint1:
  553.                         return Error;
  554.                     }
  555.                 CheckPtrExistence(AlgoWaveTable);
  556.                 /* add it to the string list */
  557.                 if (!InsertStringListElement(AlgoWaveTableList->List,NIL,NIL,AlgoWaveTable,True))
  558.                     {
  559.                      FailurePoint2:
  560.                         DisposeAlgoWaveTableObject(AlgoWaveTable);
  561.                         Error = eFileLoadOutOfMemory;
  562.                         goto FailurePoint1;
  563.                     }
  564.                 /* add it to the array */
  565.                 if (!ArrayAppendElement(AlgoWaveTableList->AlgoWaveTableArray,AlgoWaveTable))
  566.                     {
  567.                      FailurePoint3:
  568.                         RemoveStringListElement(AlgoWaveTableList->List,AlgoWaveTable,True);
  569.                         goto FailurePoint2;
  570.                     }
  571.                 /* change the name in the list */
  572.                 AlgoWaveTableListAlgoWaveTableNameChanged(AlgoWaveTableList,AlgoWaveTable);
  573.             }
  574.  
  575.         return eFileLoadNoError;
  576.     }
  577.  
  578.  
  579. /* write algorithmic wave table objects to a file.  returns True if successful. */
  580. FileLoadingErrors        AlgoWaveTableListWriteData(AlgoWaveTableListRec* AlgoWaveTableList,
  581.                                             struct BufferedOutputRec* Output)
  582.     {
  583.         long                            NumberOfObjects;
  584.         long                            Scan;
  585.  
  586.         CheckPtrExistence(AlgoWaveTableList);
  587.         CheckPtrExistence(Output);
  588.  
  589.         /*   4-byte little endian number of objects (positive 2s complement) */
  590.         NumberOfObjects = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  591.         if (!WriteBufferedSignedLongLittleEndian(Output,NumberOfObjects))
  592.             {
  593.                 return eFileLoadDiskError;
  594.             }
  595.  
  596.         /*   n-byte data for all the objects */
  597.         for (Scan = 0; Scan < NumberOfObjects; Scan += 1)
  598.             {
  599.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  600.                 FileLoadingErrors                Error;
  601.  
  602.                 /* get the object */
  603.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  604.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  605.                 /* write the object out */
  606.                 Error = AlgoWaveTableObjectWriteDataOut(AlgoWaveTableTemp,Output);
  607.                 /* handle errors */
  608.                 if (Error != eFileLoadNoError)
  609.                     {
  610.                         return Error;
  611.                     }
  612.             }
  613.  
  614.         return eFileLoadNoError;
  615.     }
  616.  
  617.  
  618. /* after a file has been saved, this is called to mark all objects as not modified. */
  619. void                                AlgoWaveTableListMarkAllObjectsSaved(
  620.                                             AlgoWaveTableListRec* AlgoWaveTableList)
  621.     {
  622.         long                            Scan;
  623.         long                            Limit;
  624.  
  625.         CheckPtrExistence(AlgoWaveTableList);
  626.         Limit = ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  627.         for (Scan = 0; Scan < Limit; Scan += 1)
  628.             {
  629.                 AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  630.  
  631.                 AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  632.                     AlgoWaveTableList->AlgoWaveTableArray,Scan);
  633.                 AlgoWaveTableObjectMarkAsSaved(AlgoWaveTableTemp);
  634.             }
  635.         AlgoWaveTableList->AlgoWaveTableListChanged = False;
  636.     }
  637.  
  638.  
  639. /* copy the selected object in the list to the clipboard.  return False if failed. */
  640. MyBoolean                        AlgoWaveTableListCopyObject(AlgoWaveTableListRec* AlgoWaveTableList)
  641.     {
  642.         ArrayRec*                            ListOfSelections;
  643.         MyBoolean                            TotalSuccessFlag = False;
  644.  
  645.         CheckPtrExistence(AlgoWaveTableList);
  646.         ListOfSelections = GetListOfSelectedItems(AlgoWaveTableList->List);
  647.         if (ListOfSelections != NIL)
  648.             {
  649.                 if (ArrayGetLength(ListOfSelections) >= 1)
  650.                     {
  651.                         AlgoWaveTableObjectRec*    AlgoWaveTableTemp;
  652.                         FileSpec*                        TempFileLocation;
  653.  
  654.                         AlgoWaveTableTemp = (AlgoWaveTableObjectRec*)ArrayGetElement(
  655.                             ListOfSelections,0);
  656.                         /* open the temporary file */
  657.                         TempFileLocation = NewTempFileSpec(CODE4BYTES('\?','\?','\?','\?'),
  658.                             CODE4BYTES('\?','\?','\?','\?'));
  659.                         if (TempFileLocation != NIL)
  660.                             {
  661.                                 FileType*                            FileDescriptor;
  662.  
  663.                                 if (OpenFile(TempFileLocation,&FileDescriptor,eReadAndWrite))
  664.                                     {
  665.                                         BufferedOutputRec*        BufferedFile;
  666.  
  667.                                         BufferedFile = NewBufferedOutput(FileDescriptor);
  668.                                         if (BufferedFile != NIL)
  669.                                             {
  670.                                                 MyBoolean                            WriteSucceeded = False;
  671.  
  672.                                                 if (WriteBufferedOutput(BufferedFile,sizeof(MAGICSCRAPSTRING),
  673.                                                     MAGICSCRAPSTRING))
  674.                                                     {
  675.                                                         if (AlgoWaveTableObjectWriteDataOut(AlgoWaveTableTemp,
  676.                                                             BufferedFile) == eFileLoadNoError)
  677.                                                             {
  678.                                                                 WriteSucceeded = True;
  679.                                                             }
  680.                                                     }
  681.                                                 if (EndBufferedOutput(BufferedFile) && WriteSucceeded)
  682.                                                     {
  683.                                                         char*                            Buffer;
  684.                                                         long                            NumberOfBytes;
  685.  
  686.                                                         NumberOfBytes = GetFileLength(FileDescriptor);
  687.                                                         Buffer = AllocPtrCanFail(NumberOfBytes,
  688.                                                             "AlgoWaveTableListCopyObject:  scrap buffer");
  689.                                                         if (Buffer != NIL)
  690.                                                             {
  691.                                                                 if (SetFilePosition(FileDescriptor,0))
  692.                                                                     {
  693.                                                                         if (0 == ReadFromFile(FileDescriptor,
  694.                                                                             Buffer,NumberOfBytes))
  695.                                                                             {
  696.                                                                                 if (SetScrapToThis(Buffer))
  697.                                                                                     {
  698.                                                                                         TotalSuccessFlag = True;
  699.                                                                                     }
  700.                                                                             }
  701.                                                                     }
  702.                                                                 ReleasePtr(Buffer);
  703.                                                             }
  704.                                                     }
  705.                                             }
  706.                                         CloseFile(FileDescriptor);
  707.                                     }
  708.                                 DeleteFile(TempFileLocation);
  709.                                 DisposeFileSpec(TempFileLocation);
  710.                             }
  711.                     }
  712.                 DisposeArray(ListOfSelections);
  713.             }
  714.         return TotalSuccessFlag;
  715.     }
  716.  
  717.  
  718. /* try to paste the clipboard in as an algorithmic wave table object.  returns False if */
  719. /* it failed or the clipboard did not contain an algorithmic wave table object. */
  720. MyBoolean                        AlgoWaveTableListPasteObject(AlgoWaveTableListRec* AlgoWaveTableList)
  721.     {
  722.         MyBoolean                    TotalSuccessFlag = False;
  723.         char*                            Scrap;
  724.  
  725.         CheckPtrExistence(AlgoWaveTableList);
  726.         Scrap = GetCopyOfScrap();
  727.         if (Scrap != NIL)
  728.             {
  729.                 FileSpec*                    TempFileLocation;
  730.  
  731.                 TempFileLocation = NewTempFileSpec(CODE4BYTES('\?','\?','\?','\?'),
  732.                     CODE4BYTES('\?','\?','\?','\?'));
  733.                 if (TempFileLocation != NIL)
  734.                     {
  735.                         FileType*                            FileDescriptor;
  736.  
  737.                         if (OpenFile(TempFileLocation,&FileDescriptor,eReadAndWrite))
  738.                             {
  739.                                 BufferedOutputRec*        BufferedFile;
  740.  
  741.                                 BufferedFile = NewBufferedOutput(FileDescriptor);
  742.                                 if (BufferedFile != NIL)
  743.                                     {
  744.                                         MyBoolean                            WriteSucceeded = False;
  745.  
  746.                                         if (WriteBufferedOutput(BufferedFile,PtrSize(Scrap),Scrap))
  747.                                             {
  748.                                                 WriteSucceeded = True;
  749.                                             }
  750.                                         if (EndBufferedOutput(BufferedFile) && WriteSucceeded)
  751.                                             {
  752.                                                 TotalSuccessFlag = AlgoWaveTableListPasteFromFile(
  753.                                                     AlgoWaveTableList,FileDescriptor);
  754.                                             }
  755.                                     }
  756.                                 CloseFile(FileDescriptor);
  757.                             }
  758.                         DeleteFile(TempFileLocation);
  759.                         DisposeFileSpec(TempFileLocation);
  760.                     }
  761.                 ReleasePtr(Scrap);
  762.             }
  763.         return TotalSuccessFlag;
  764.     }
  765.  
  766.  
  767. /* try to paste the algorithmic wave table object in from the file */
  768. MyBoolean                        AlgoWaveTableListPasteFromFile(AlgoWaveTableListRec* AlgoWaveTableList,
  769.                                             struct FileType* File)
  770.     {
  771.         MyBoolean                    TotalSuccessFlag = False;
  772.  
  773.         CheckPtrExistence(AlgoWaveTableList);
  774.         if (SetFilePosition(File,0))
  775.             {
  776.                 BufferedInputRec*    InputFile;
  777.  
  778.                 InputFile = NewBufferedInput(File);
  779.                 if (InputFile != NIL)
  780.                     {
  781.                         char                            HeaderTest[sizeof(MAGICSCRAPSTRING)];
  782.  
  783.                         if (ReadBufferedInput(InputFile,sizeof(MAGICSCRAPSTRING),HeaderTest))
  784.                             {
  785.                                 if (MemEqu(MAGICSCRAPSTRING,HeaderTest,sizeof(MAGICSCRAPSTRING)))
  786.                                     {
  787.                                         AlgoWaveTableObjectRec*        AlgoWaveTableTemp EXECUTE(= (AlgoWaveTableObjectRec*)0x81818181);
  788.  
  789.                                         if (eFileLoadNoError == AlgoWaveTableObjectNewFromFile(&AlgoWaveTableTemp,
  790.                                             InputFile,AlgoWaveTableList->CodeCenter,AlgoWaveTableList->MainWindow,
  791.                                             AlgoWaveTableList))
  792.                                             {
  793.                                                 CheckPtrExistence(AlgoWaveTableTemp);
  794.                                                 /* add it to the scrolling object list */
  795.                                                 if (!InsertStringListElement(AlgoWaveTableList->List,NIL,NIL,AlgoWaveTableTemp,True))
  796.                                                     {
  797.                                                      FailurePoint:
  798.                                                         DisposeAlgoWaveTableObject(AlgoWaveTableTemp);
  799.                                                     }
  800.                                                  else
  801.                                                     {
  802.                                                         MainWindowDeselectAllOtherStringLists(AlgoWaveTableList->MainWindow,
  803.                                                             AlgoWaveTableList);
  804.                                                         SelectStringListElement(AlgoWaveTableList->List,AlgoWaveTableTemp);
  805.                                                         MakeStringListSelectionVisible(AlgoWaveTableList->List);
  806.                                                         /* add it to the array */
  807.                                                         if (!ArrayAppendElement(AlgoWaveTableList->AlgoWaveTableArray,AlgoWaveTableTemp))
  808.                                                             {
  809.                                                                 RemoveStringListElement(AlgoWaveTableList->List,AlgoWaveTableTemp,True);
  810.                                                                 goto FailurePoint;
  811.                                                             }
  812.                                                          else
  813.                                                             {
  814.                                                                 /* change the name in the list */
  815.                                                                 AlgoWaveTableListAlgoWaveTableNameChanged(AlgoWaveTableList,AlgoWaveTableTemp);
  816.                                                                 TotalSuccessFlag = True;
  817.                                                                 AlgoWaveTableList->AlgoWaveTableListChanged = True;
  818.                                                             }
  819.                                                     }
  820.                                             }
  821.                                     }
  822.                             }
  823.                         EndBufferedInput(InputFile);
  824.                     }
  825.             }
  826.         return TotalSuccessFlag;
  827.     }
  828.  
  829.  
  830. /* find out how many algorithmic wave tables there are in this list */
  831. long                                AlgoWaveTableListHowMany(AlgoWaveTableListRec* AlgoWaveTableList)
  832.     {
  833.         CheckPtrExistence(AlgoWaveTableList);
  834.         return ArrayGetLength(AlgoWaveTableList->AlgoWaveTableArray);
  835.     }
  836.  
  837.  
  838. /* get an indexed algorithmic wave tables from the list */
  839. struct AlgoWaveTableObjectRec*    AlgoWaveTableListGetIndexedAlgoWaveTable(
  840.                                             AlgoWaveTableListRec* AlgoWaveTableList, long Index)
  841.     {
  842.         AlgoWaveTableObjectRec*    AlgoWaveTable;
  843.  
  844.         CheckPtrExistence(AlgoWaveTableList);
  845.         ERROR((Index < 0) || (Index >= AlgoWaveTableListHowMany(AlgoWaveTableList)),
  846.             PRERR(ForceAbort,"AlgoWaveTableListGetIndexedAlgoWaveTable:  index out of range"));
  847.         AlgoWaveTable = (AlgoWaveTableObjectRec*)ArrayGetElement(
  848.             AlgoWaveTableList->AlgoWaveTableArray,Index);
  849.         CheckPtrExistence(AlgoWaveTable);
  850.         return AlgoWaveTable;
  851.     }
  852.